package initalize

import (
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/consumer"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"go.uber.org/zap"

	"application/global"
)

func InitConsumer() {
	var err error
	global.PushConsumer, err = rocketmq.NewPushConsumer(
		consumer.WithGroupName(""),
		consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{"127.0.0.1:9876"})),
	)
	if err != nil {
		zap.S().Error("消费者初始化失败！", err.Error())
		return
	}
	err = global.PushConsumer.Start()
	if err != nil {
		zap.S().Error("消费者开启失败！", err.Error())
		return
	}
	zap.S().Info("消费者开启成功！")
}
